package com.whsxt.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whsxt.domain.ProdProp;
import com.whsxt.domain.ProdPropValue;
import com.whsxt.service.ProdPropService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-03-16 14:10
 * @Description:
 */
@RestController
@RequestMapping("/prod/spec")
@Api(tags = "商品的属性管理接口")
public class ProdPropController {


    @Autowired
    private ProdPropService prodPropService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询商品的属性和属性值")
    public ResponseEntity<IPage<ProdProp>> prodPropPage(Page<ProdProp> page, ProdProp prodProp) {
        IPage<ProdProp> iPage = prodPropService.findProdPropPage(page, prodProp);
        return ResponseEntity.ok(iPage);
    }


    @PostMapping
    @ApiOperation(value = "新增商品属性")
    public ResponseEntity<Void> addProdProp(@RequestBody ProdProp prodProp) {
        prodPropService.save(prodProp);
        return ResponseEntity.ok().build();
    }


    @GetMapping("/list")
    @ApiOperation(value = "查询产品的属性和属性值")
    public ResponseEntity<List<ProdProp>> findAllProdProp() {
        List<ProdProp> list = prodPropService.list();
        return ResponseEntity.ok(list);
    }


    @GetMapping("/listSpecValue/{id}")
    @ApiOperation(value = "根据商品属性id查询属性值集合")
    public ResponseEntity<List<ProdPropValue>> findProdPropValueByPropId(@PathVariable("id") Long id) {
        List<ProdPropValue> list = prodPropService.findProdPropValueByPropId(id);
        return ResponseEntity.ok(list);
    }


}
